package com.teichmann.engine;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.teichmann.bo.Car;
import com.teichmann.core.OnlinePage;
import com.teichmann.core.Page;
import com.teichmann.services.CarServices;

public class CarSearch {

	private ArrayList<Car> returnedCars;
	private Page[] pages;
	private OnlinePage[] onlinePages;
	
	public CarSearch(List<Page> pages) {
		this.pages = pages.toArray(new Page[0]);
	}

	public CarSearch(Page[] pages) {
		this.pages = pages;
	}
	
	public CarSearch(ArrayList<OnlinePage> onlinePages) {
		this.onlinePages = onlinePages.toArray(new OnlinePage[0]);
	}

	public CarSearch(OnlinePage[] pages) {
		this.onlinePages = pages;
	}
	
	public void process(String parameter) throws IOException {
		
		returnedCars = new ArrayList<Car>();
		for (OnlinePage p : onlinePages) {
			returnedCars.addAll(p.performSearch(parameter));
		}
		
		CarServices.updateFoundCars(returnedCars);
		
	}
	
	

	public void process() throws IOException {
		returnedCars = new ArrayList<Car>();
		for (Page p : pages) {
			returnedCars.addAll(p.performSearch());
		}
		
		CarServices.updateFoundCars(returnedCars);
		
	}

}
